﻿using System;
using System.Data;
using System.Text;
using System.Web.UI.HtmlControls;

namespace LKCMS.Web
{
    public partial class GuestList : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            if (!Page.IsPostBack)
            {
                BindMeta("咨询留言");
                Bind();

            }
        }

        private void BindMeta(string classname)
        {
            LKCMS.Model.WebSet webset = new LKCMS.BLL.WebSet().loadConfig(LKCMS.Common.Utils.GetXmlMapPath("Configpath"));

            Page.Title = classname + "_" + webset.WebKeywords;


            //Encode/Content type
            HtmlMeta encode = new HtmlMeta();
            encode.HttpEquiv = "Content-Type";
            encode.Content = "text/html; charset=utf-8";
            Page.Header.Controls.Add(encode);

            //Language
            HtmlMeta lang = new HtmlMeta();
            lang.HttpEquiv = "Content-Language";
            lang.Content = "zh-cn";
            Page.Header.Controls.Add(lang);

            //Description
            HtmlMeta desc = new HtmlMeta();
            desc.Name = "Description";
            desc.Content = webset.WebDescription;
            Page.Header.Controls.Add(desc);

            //Keyword
            HtmlMeta keywords = new HtmlMeta();
            keywords.Name = "keywords";
            keywords.Content = webset.WebKeywords;
            Page.Header.Controls.Add(keywords);

        }
        private void Bind()
        {
            StringBuilder sb = new StringBuilder();
            LKCMS.BLL.Channel bll = new LKCMS.BLL.Channel();
            LKCMS.BLL.Pictures pll = new LKCMS.BLL.Pictures();
            LKCMS.Model.Channel model = bll.GetModel(1);


            //最近更新
            sb.Append("<div class=\"right_block\">");
            sb.Append("<div class=\"right_block_title\">");
            sb.Append("<div class=\"left_block_title_text\"><strong>" + model.Title + "</strong>最近更新</div>");
            sb.Append("</div>");
            sb.Append("<div class=\"right_block_content\">");
            sb.Append("<ul>");

            string s = bll.GetChannels(model.Id).ToString();
            if (s != "")
            {

                DataTable dtzj = pll.GetList(15, " ClassId in (" + s + ")", " AddTime desc,Click desc").Tables[0];
                foreach (DataRow dr1 in dtzj.Rows)
                {
                    sb.Append("<li>. <a href=\"DetailTW.aspx?id=" + dr1["ID"].ToString() + "\" title=\"" + dr1["Title"].ToString() + "/ " + dr1["AddTime"].ToString() + "\" target=\"_blank\">" + dr1["Title"].ToString() + "</a></li>");
                }
            }
            sb.Append(" </ul>");
            sb.Append("</div>");
            sb.Append("</div>  ");

            //最热
            sb.Append("<div class=\"right_block\">");
            sb.Append("<div class=\"right_block_title\">");
            sb.Append("<div class=\"left_block_title_text\"><strong>" + model.Title + "</strong>热点</div>");
            sb.Append("</div>");
            sb.Append("<div class=\"right_block_content\">");
            sb.Append("<ul>");

            if (s != "")
            {
                DataTable dtzr = pll.GetList(15, " ClassId in (" + s + ")", " Click desc,AddTime desc").Tables[0];
                foreach (DataRow dr2 in dtzr.Rows)
                {
                    sb.Append("<li>. <a href=\"DetailTW.aspx?id=" + dr2["ID"].ToString() + "\" title=\"" + dr2["Title"].ToString() + "/ " + dr2["Click"].ToString() + " Hits\" target=\"_blank\">" + dr2["Title"].ToString() + "</a></li>");
                }
            }
            sb.Append(" </ul>");
            sb.Append("</div>");
            sb.Append("</div>  ");
            this.LiteraClassType.Text = sb.ToString();
            BindContent(0);

        }



        private void BindContent(int currentpage)
        {
            StringBuilder sb = new StringBuilder();
            LKCMS.BLL.Feedback bll = new LKCMS.BLL.Feedback();
   
            int totalcount = 0;
            int pagesize = 10;

            DataTable dt = bll.GetPageList(8, currentpage, " IsLock=1", "AddTime desc").Tables[0];
            totalcount = bll.GetCount(" IsLock=1"); 




                    foreach (DataRow dr in dt.Rows)
                    {
                        sb.Append("<div id=\"mt\">");
                        sb.Append("<span style=\"font-size:11px\">Poster:" + dr["UserName"].ToString() + "</span>&nbsp;&nbsp;");
                        sb.Append("<span style=\"font-size:11px\">Email:" + dr["UserEmail"].ToString() + "</span>&nbsp;&nbsp;<span style=\"font-size:11px\">Phone No ." + dr["UserTel"].ToString() + "</span> &nbsp;&nbsp;<span style=\"font-size:11px\">QQ ." + dr["UserQQ"].ToString() + "</span>");
                         sb.Append("</span>");
                         sb.Append("</div>");
                         sb.Append("<div id=\"mc\"><div id=\"ar\">>></div>");
                         sb.Append("<div id=\"mc2\"><font class=newstitle>" + dr["Content"].ToString() + "</font></div>");
                         if (dr["ReContent"].ToString().Trim() != "" && dr["ReContent"].ToString().Trim()!=null)
                         {
                             sb.Append("<div id=\"mr\"><span class=\"newstitle\"><b><u>" + dr["ReUser"].ToString() + " Reply:</u></b></span><br><span class=guestreply>" + dr["ReContent"].ToString() + "</span></div>");
                             sb.Append("<div id=\"re\"><span style=\"font-size:11px\">&nbsp;&nbsp;&nbsp;回复于：</span><font color=f0f0f0 size=1>" + dr["ReTime"].ToString() + "</font></div></div>");
                         }
                         else
                         {
                             sb.Append("<div id=\"re\"><span style=\"font-size:11px\">&nbsp;&nbsp;&nbsp;发表于：</span><font color=f0f0f0 size=1>" + dr["AddTime"].ToString() + "</font></div></div>");
                         }
                         sb.Append("<br><br>");
                        sb.Append("<div id=\"d_line\"><img src=\"images/m_line_hor.jpg\" width=\"640\" height=\"2\"></div><br>");
                    }

            this.AspNetPager1.RecordCount = totalcount;
            this.AspNetPager1.PageSize = pagesize;
            this.LiteralContent.Text = sb.ToString();
           
         
        }




        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
           
            BindContent(this.AspNetPager1.CurrentPageIndex);
        }
    }
}
